package com.neulogistics.core.substation.infrastructure.persistence.repository;

import com.neulogistics.core.substation.domain.model.aggregate.SubstationPayment;
import com.neulogistics.core.substation.domain.repository.ISubstationPaymentRepository;
import com.neulogistics.core.substation.infrastructure.persistence.converter.SubstationPaymentEntityPOConverter;
import com.neulogistics.core.substation.infrastructure.persistence.orm.po.SubstationPaymentPO;
import com.neulogistics.core.substation.infrastructure.persistence.orm.service.ISubstationPaymentPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class SubstationPaymentRepository implements ISubstationPaymentRepository {
    @Resource
    private ISubstationPaymentPOService substationPaymentPOService;

    @Override
    public void save(SubstationPayment substationPayment) {
        SubstationPaymentPO substationPaymentPO = SubstationPaymentEntityPOConverter.entityToPO(substationPayment);
        substationPaymentPOService.saveOrUpdate(substationPaymentPO);
    }

    @Override
    public SubstationPayment findById(Long id) {
        SubstationPaymentPO substationPaymentPO = substationPaymentPOService.getById(id);
        SubstationPayment substationPayment = SubstationPaymentEntityPOConverter.POToEntity(substationPaymentPO);
        return substationPayment;
    }

    @Override
    public void deleteById(Long id) {
        substationPaymentPOService.removeById(id);
    }
}
